import { SERVER_URL } from "../config/index.js"

const $http = (url, data = {}, method = "get", header) => {
	// let deal_url = `${SERVER_URL}:${SERVER_PORT}/${url}`
	let deal_url = `${SERVER_URL}/${url}`
	
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title: "加载中"
		})
		uni.request({
			url: deal_url,
			method,
			header,
			data,
			success(res) {
				uni.hideLoading();
				resolve(res)
			},
			fail(err) {
				uni.showToast({
					icon: "none",
					title: "网络出了差错,请重试"
				})
				reject(err)
			}
		})
	})
}

export default $http;